#!/usr/bin/env python

import wx
import component

class Main(component.Interactor):
    '''Main class
    
    @author Julot <andy.julot@gmail.com>
    @since Saturday, January 14, 2012. 09:04 AM'''
    
    def bind(self):
        super(Main, self).bind()
        
        view = self.view
        menu = view.MenuBar
        tool = view.ToolBar
        
        view.Bind(wx.EVT_TIMER, self.onTimer)
        
        view.Bind(wx.EVT_MENU, self.close, menu.file.close)
        view.Bind(wx.EVT_MENU, self.reply, menu.message.reply)
        view.Bind(wx.EVT_MENU, self.archive, menu.message.archive)
        view.Bind(wx.EVT_MENU, self.delete, menu.message.delete)
        view.Bind(wx.EVT_MENU, self.recover, menu.message.recover)
        view.Bind(wx.EVT_MENU, self.export, menu.message.export)
        view.Bind(wx.EVT_MENU, self.showAbout, menu.help.about)
        
        view.Bind(wx.EVT_MENU, self.close, tool.close.tool)
        view.Bind(wx.EVT_MENU, self.reply, tool.reply.tool)
        view.Bind(wx.EVT_MENU, self.archive, tool.archive.tool)
        view.Bind(wx.EVT_MENU, self.delete, tool.delete.tool)
        view.Bind(wx.EVT_MENU, self.recover, tool.recover.tool)
        view.Bind(wx.EVT_MENU, self.export, tool.export.tool)
        view.Bind(wx.EVT_MENU, self.showAbout, tool.about.tool)
        
        view.Bind(wx.EVT_LISTBOX, self.filter, view.labels)
        view.Bind(wx.EVT_LIST_ITEM_SELECTED, self.viewMessage, view.messages)
        view.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.clearMessage, view.messages)
    
    def close(self, event):
        self.presenter.close()
        event.Skip()
    
    def showAbout(self, event):
        self.presenter.showAbout()
        event.Skip()
    
    def filter(self, event):
        self.presenter.clearMessage()
        self.presenter.filter(event.String)
    
    def viewMessage(self, event):
        event.Skip()
        self.presenter.viewMessage(event.Data)
    
    def onTimer(self, event):
        self.presenter.onTimer()
    
    def export(self, event):
        path = self.presenter.confirmExport()
        if path: self.presenter.export(path)
    
    def clearMessage(self, event):
        self.presenter.clearMessage()
    
    def archive(self, event):
        self.presenter.archive()
    
    def delete(self, event):
        self.presenter.delete()
    
    def recover(self, event):
        self.presenter.recover()
    
    def reply(self, event):
        self.presenter.reply()
        